﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Configuration;

public partial class admin_DoiMatKhau : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnOK_OnClick(object sender, EventArgs e)
    {
        Configuration webconfig = WebConfigurationManager.OpenWebConfiguration("~");

        SystemWebSectionGroup sysweb = (SystemWebSectionGroup)webconfig.GetSectionGroup("system.web");

        AuthenticationSection authSection = sysweb.Authentication;

        FormsAuthenticationUserCollection users = authSection.Forms.Credentials.Users;

        FormsAuthenticationUser user = users[User.Identity.Name]; //you can grab it from a textbox or User.Identity.Name ~ current LoggedIn User

        if (user.Password != txtPassword1.Text)
        {
            ClientScript.RegisterStartupScript(typeof(Page), "testScript", "thatbai()", true);
            return;
        }
        user.Password = txtPassword2.Text; //you can grab it from a textbox......

        webconfig.Save();
        ClientScript.RegisterStartupScript(typeof(Page), "testScript", "thanhcong()", true);
    }
}